package binarysearch.test69;

/**
 * x 的平方根
 *
 * @author code_yc
 * @version 1.0
 * @date 2020/7/11 9:57
 */
public class Solution1 {

    // 二分右查找
    public int mySqrt(int x) {
        if (x == 0) return 0;
        int l = 1;
        int r = x;
        while (l < r) {
            int mid = l + ((r - l + 1) >> 1);
            if (mid <= x / mid) l = mid;
            else r = mid - 1;
        }
        return r;
    }
}
